package com.atguigu.spzx.order.controller;

import com.atguigu.spzx.model.dto.h5.OrderInfoDto;
import com.atguigu.spzx.model.entity.order.OrderInfo;
import com.atguigu.spzx.model.vo.common.Result;
import com.atguigu.spzx.model.vo.common.ResultCodeEnum;
import com.atguigu.spzx.model.vo.h5.TradeVo;
import com.atguigu.spzx.order.service.OrderInfoService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName: OrderInfoController
 * @Package: com.atguigu.spzx.order.controller
 * @Description 订单管理
 * @Author 孤妤
 * @Date: 2023/12/20 18:09
 */
@Tag(name = "订单管理")
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {
    @Autowired
    private OrderInfoService orderInfoService;
    @Operation(summary = "查询结算页面商品列表与结算金额")
    @GetMapping("/auth/trade")
    public Result findOrderInfo(){
        TradeVo tradeVo = orderInfoService.findOrderInfo();
        return Result.build(tradeVo, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "提交订单")
    @PostMapping("/auth/submitOrder")
    public Result submitOrder(@RequestBody OrderInfoDto orderInfoDto){
        Long orderNo = orderInfoService.submitOrder(orderInfoDto);
        return Result.build(orderNo,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/{orderId}")
    @Operation(summary = "支付页面")
    public Result findOrderInfoByOrderId(@PathVariable Long orderId){
        OrderInfo orderInfo = orderInfoService.findOrderInfoByOrderId(orderId);
        return Result.build(orderInfo,ResultCodeEnum.SUCCESS);
    }
    @GetMapping("/auth/buy/{skuId}")
    @Operation(summary = "立即购买")
    public Result findOrderInfoBySkuId(@PathVariable Long skuId){
        TradeVo tradeVo = orderInfoService.findOrderInfoBySkuId(skuId);
        return Result.build(tradeVo,ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "我的订单")
    @GetMapping("/auth/{page}/{limit}")
    public Result findMyOrderPage(@PathVariable Integer page,
                                  @PathVariable Integer limit,
                                  @RequestParam(required = false) Integer orderStatus){
        PageInfo<OrderInfo> orderInfoPageInfo = orderInfoService.findMyOrderPage(page,limit,orderStatus);
        return Result.build(orderInfoPageInfo,ResultCodeEnum.SUCCESS);
    }
}
